package com.hxzy.module.store.controller;

import com.github.pagehelper.PageInfo;
import com.hxzy.framework.common.resp.R;
import com.hxzy.framework.common.resp.ResultCode;
import com.hxzy.framework.web.util.WebFrameworkUtils;
import com.hxzy.module.store.api.store.req.StoreReq;
import com.hxzy.module.store.api.store.resp.StoreResp;
import com.hxzy.module.store.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Author wy
 * @Description TODO
 * @Date 2024/1/24 14:26
 * @Version 1.0
 */
@RestController
@Api( tags= "门店模块-门店Api")
@RequestMapping("/storeManage")
public class StoreController {


    @Autowired
    private StoreService storeService;

    @ApiOperation(value ="门店列表" )
    @GetMapping(value = "/storeList")
    public R<PageInfo<StoreResp>> storeList(@Validated StoreReq req){
       PageInfo<StoreResp> pageInfo=this.storeService.storeList(req);
       return R.success(pageInfo);
    }

    @ApiOperation(value  = "根据storeId查询数据")
    @GetMapping(value = "/{storeId}")
    public R<StoreResp> findByStoreId( @PathVariable(value = "storeId") Long storeId){
        long merchantId= WebFrameworkUtils.getMerchantId();
        StoreResp resp= this.storeService.findByStoreId(storeId,merchantId);
        if(Objects.isNull(resp)){
            return R.failed(ResultCode.DATA_NOT_FOUND);
        }
        return R.success(resp);
    }




}
